﻿window.onscroll = function() {
    OnPageScroll();
}

$(document).ready(function() {
    var x = $.cookie(window.location.pathname + "-X");
    var y = $.cookie(window.location.pathname + "-Y");
    
    if (window.pageYOffset) {    // all except IE   
        window.pageYOffset = y;
        window.pageXOffset = x;
    }
    else if (document.documentElement && document.documentElement.scrollTop) 
    {    // IE 6 Strict
        document.documentElement.scrollTop = y;
        document.documentElement.scrollLeft = x;
    } else if (document.body) 
    {    // all other IE
        document.body.scrollTop = y;
        document.body.scrollLeft = x;
    }
});

//滚动时
function OnPageScroll() {
    //获取滚动条的位置
    var scrollpoint = GetPageScroll();

    //记录滚动条的位置
    $.cookie(window.location.pathname + "-X", scrollpoint.X);
    $.cookie(window.location.pathname + "-Y", scrollpoint.Y);
}

//获取滚动条的位置
function GetPageScroll() {
    var x, y;
    if (window.pageYOffset) {    // all except IE   
        y = window.pageYOffset;
        x = window.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {    // IE 6 Strict   
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    } else if (document.body) {    // all other IE   
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    }
    return { X: x, Y: y };
}